package someTestExcemple.huaweiOd.container.array;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class SimpleMemoryPoolReview {
    private static final int MAX_SIZE = 100;
    private static final String  ERROR = "error";
    private static final String REQUEST = "REQUEST";
    private static final String RELEASE = "RELEASE";
    private static Map<Integer,Integer> map = new HashMap<>();

    /**
     * 4
     * REQUEST=20
     * REQUEST=30
     * RELEASE=0
     * REQUEST=30
     *
     */

    public static void main(String[] args) {
        try {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            String[][] records = new String[N][2];
            for (int i = 0; i < N; i++) {
                String[] record = sc.next().split("=");
                records[i][0] = record[0];
                records[i][1] = record[1];
            }
            /**
             *             // 接下来的N行，每行将给出一个操作命令，操作命令和参数之间用“=”分割
             *             for (int i = 0; i < N; i++) {
             *                 lineArr[i] = sc.nextLine().split("=");
             *             }
             */
            System.out.println(Arrays.deepToString(records));
            for (int i = 0; i < N; i++) {
                if (records[i][0].startsWith(REQUEST)) {
                    //请求内存
                    if (Integer.parseInt(records[i][1]) > MAX_SIZE || Integer.parseInt(records[i][1]) <= 0) {
                        System.out.println(ERROR);
                        break;
                    }
                    request(Integer.parseInt(records[i][1]));
                } else if (records[i][0].startsWith(RELEASE)) {
                    map.remove(records[i][1]);
                } else {
                    System.out.println(ERROR);
                }
            }
        } catch (Exception e) {
            System.out.println(ERROR);
        }
    }

    public static void request(int size) {
        int beforeFreeAddress = 0;
        if (map.isEmpty()) {
            map.put(beforeFreeAddress, size);
            System.out.println(beforeFreeAddress);
            return;
        }
        for (Integer address : map.keySet()) {
            if (address - beforeFreeAddress >= size) {
                map.put(beforeFreeAddress, beforeFreeAddress + size);
            } else {
                beforeFreeAddress = map.get(address);
            }
        }
        if (MAX_SIZE - beforeFreeAddress >= size) {
            map.put(beforeFreeAddress, beforeFreeAddress + size);
            System.out.println(beforeFreeAddress);
        } else {
            System.out.println("-1");
        }
    }
}
